<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="div1">
        <div id="div2">
            <div id="div3">
                <div id="div4">ggg</div>
            </div>
            <div></div>
        </div>
    </div>
    <script>
        let range1 = document.createRange();
        range1.selectNode(div1);

        // 精确选择
        range1.setStartAfter(div3);
        range1.setEndAfter(div2);
    </script>
</body>

</html>